/*
# File    :   events_demo.c
# Author  :   SCHIPS
# Mail    :   schips@dingtalk.com
# Git     :   https://gitee.com/schips/
# Date    :   Mon, May 27, 2019  7:35:22 PM
*/

#include <stdio.h>
#include "events.h"

int dispatch(Event *event)
{
    printf("event type = %d\n", event->type);
}

int main(int argc, char *argv[])
{
    Event app_event ;
    Queue events = {0};  // 使用之前要清空
    int i;
    for(i = 0; i < 5; i++)
    {
        app_event.type = i;

        receive_event(&events, &app_event);
        printf("Add event %d\n", app_event.type);
    }

    app_event.type = 2;
    receive_event(&events, &app_event);
    printf("Add event %d\n", app_event.type);
	
    process_event(&events, dispatch);
    for(;;)
    {
        i = process_event(&events, dispatch);
        if (i != 0) break;
    }

    return 0;
}
